var t = require;
var e = module;
var o = exports;
var a,
    i =
    (this && this.__extends) ||
    ((a = function(t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({ __proto__: [] }
                    instanceof Array &&
                    function(t, e) {
                        t.__proto__ = e;
                    }) ||
                function(t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function(t, e) {
            a(t, e);

            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
    (this && this.__decorate) ||
    function(t, e, o, a) {
        var i,
            n = arguments.length,
            r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
        else
            for (var s = t.length - 1; s >= 0; s--)
                (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
        return n > 3 && r && Object.defineProperty(e, o, r), r;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var r = t("UIConfig"),
    s = t("UIManager"),
    c = t("GameCof"),
    p = t("AdView"),
    l = cc._decorator,
    d = l.ccclass,
    u = l.property,
    h =
    (l.menu,
        (function(t) {
            i(e, t);

            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.G_Mat = null;
                e.W_Mat = null;
                e.camera = null;
                e.firstEnterLogin = !1;
                e.updateCheckCall = [];
                e.addTimeLab = !1;
                e.addCostPay = !1;
                e.firstSendData = !1;
                return e;
            }
            e.prototype.onLoad = function() {
                var t = this;
                CacheDataManager.G_Mat = this.G_Mat;
                CacheDataManager.W_Mat = this.W_Mat;
                s.default.open(r.UIID.UIAdpOffect);
                s.default.open(r.UIID.UILoading, {
                    tip: "场景准备中...",
                    darkOver: function() {
                        t.firstEnterLogin = !0;
                    }
                });
                SdkManager.init(function() {
                    console.log("初始化sdk");
                });
                this.initEnterCofUI();
                this.initServerData();
                try {
                    AdView.setAdConfig();
                } catch (t) {
                    console.log("读取广告配置失败", t);
                }
            };
            e.prototype.initServerData = function() {
                if (!this.addTimeLab) {
                    this.addTimeLab = !0;
                    this.schedule(this.addTime, 1);
                }
            };
            e.prototype.addTime = function() {
                GameBaseManager.updateAddTime();
            };
            e.prototype.initEnterCofUI = function() {
                CacheDataManager.debugAd = !1;
                if (c.default.isWk) SdkManager.login();
                else {
                    this.openPrivacyCheck();
                    c.default.setLoginData();
                }
            };
            e.prototype.initAccount = function() {
                if ("" != c.default.UID && c.default.isLoginOver() && !c.default.isInitAccount) {
                    var t = c.default.getSaveId();
                    GameDataValue.initAccount(t);
                    GuildCache.initAccount(t);
                    PlayerData.initAccount(t);
                    PayData.initAccount(t);
                    c.default.isInitAccount = !0;
                    c.default.isWk && (this.addCostPay = !0);
                }
            };
            e.prototype.openPrivacyCheck = function() {
                // if ("1" != c.default.getprivacy() && "tt" != AdView.curPlat) s.default.open(r.UIID.UIPrivacy);
                // else {
                GameBaseManager.sendAndroidInit();
                GameBaseManager.privacyIsOver = !0;
                if ("1" == c.default.getFCM() || c.default.isMiniGame) {
                    GameBaseManager.startEnterGame = !0;
                    var t = c.default.getLastId();
                    "tt" == AdView.curPlat ?
                        GameBaseManager.sendFirstEnterGame() :
                        GameBaseManager.checkLogin("", t, "", function() {
                            GameBaseManager.sendFirstEnterGame();
                        });
                    GameBaseManager.checkEnterZhuce();
                } else GameBaseManager.checkViewFanChenmi();
                // }
            };
            e.prototype.update = function() {
                this.initAccount();
                if (GameBaseManager.privacyIsOver) {
                    GameBaseManager.privacyIsOver = !1;
                    this.addAdData();
                }
                if (!this.firstSendData && GameBaseManager.startEnterGame) {
                    this.firstSendData = !0;
                    QReport.send("1001");
                    QReport.sendOnce("1003");
                }
                if (
                    this.firstEnterLogin &&
                    GameBaseManager.startEnterGame &&
                    PlayerData.canLoadData &&
                    PlayerData.canEnterGame() &&
                    c.default.isLoginOver() &&
                    c.default.isInitAccount
                ) {
                    this.firstEnterLogin = !1;
                    GameBaseManager.startEnterGame = !1;
                    s.default.open(r.UIID.UIGameData);
                }
                for (var t = 0; t < this.updateCheckCall.length; t++) {
                    var e = this.updateCheckCall.pop();
                    e.cb && e.cb(e.bool);
                    break;
                }
                PayData.udpateCall();
                if (this.addCostPay && PlayerData.canEnterGame()) {
                    this.addCostPay = !1;
                    SdkManager.reissueReward(c.default.backOrders, !0);
                }
            };
            e.prototype.onDestroy = function() {};
            e.prototype.enterGameInit = function() {
                cc.director.getCollisionManager().enabled = !0;
                cc.director.getCollisionManager().enabledDrawBoundingBox = !0;
            };
            e.prototype.addAdData = function() {
                var t = this,
                    e = {};
                if (CacheDataManager.debugAd);
                else {
                    e[1] = AdView.getAdBase().getAdData(
                        c.default.adIds.bannerId,
                        c.default.adIds.rewardAdId,
                        c.default.adIds.interstitialAdId,
                        c.default.adIds.nativeAdId,
                        c.default.adIds.customAdIds[1],
                        c.default.adIds.portalAdId
                    );
                    if ("oppo" == c.default.curPlat) {
                        e[1][p.AdPosEm.custom].preLoad();
                        e[2] = AdView.getAdBase().getAdData(
                            "",
                            "",
                            "",
                            c.default.adIds.nativeAdId,
                            c.default.adIds.customAdIds[2],
                            ""
                        );
                        e[2][p.AdPosEm.custom].setConfig({ top: 700 });
                        e[2][p.AdPosEm.custom].preLoad();
                    }
                    if ("vivo" == c.default.curPlat) {
                        e[2] = AdView.getAdBase().getAdData(
                            "",
                            "",
                            "",
                            c.default.adIds.nativeAdId,
                            c.default.adIds.customAdIds[2],
                            ""
                        );
                        e[2][p.AdPosEm.custom].preLoad();
                    }
                }
                var o = {
                    show: function(o, a, i, n, c) {
                        QReport.send("2001");
                        if (PayData.getMouthCount() > 0) {
                            s.default.open(r.UIID.AdViewCom);
                            t.scheduleOnce(function() {
                                s.default.closeUiByUIID(r.UIID.AdViewCom);
                                QReport.send("2002");
                                t.updateCheckCall.push({ cb: o, bool: !0 });
                            }, 0.2);
                        } else if (CacheDataManager.debugAd) {
                            s.default.open(r.UIID.AdViewCom);
                            t.scheduleOnce(function() {
                                s.default.closeUiByUIID(r.UIID.AdViewCom);
                                QReport.send("2002");
                                t.updateCheckCall.push({ cb: o, bool: !0 });
                            }, 2);
                        } else {
                            t.scheduleOnce(function() {
                                s.default.closeUiByUIID(r.UIID.AdViewCom);
                            }, 4);
                            if (e[n][c].isCanPlay()) {
                                c == p.AdPosEm.rewardVideo && s.default.open(r.UIID.AdViewCom);
                                e[n][c].show(function(a) {
                                    AudioManager.setPlayMusic(!AudioManager.isPlayMusic());
                                    AudioManager.setPlayMusic(!AudioManager.isPlayMusic());
                                    if (a) {
                                        QReport.send("2002");
                                        t.updateCheckCall.push({ cb: o, bool: !0 });
                                    } else t.updateCheckCall.push({ cb: o, bool: !1 });
                                    t.scheduleOnce(function() {
                                        e[n][c].preLoad && e[n][c].preLoad();
                                    }, 0.2);
                                    c == p.AdPosEm.rewardVideo && s.default.closeUiByUIID(r.UIID.AdViewCom);
                                });
                            } else if (2 == c) {
                                e[n][c].preLoad ?
                                    console.log("Login ----------------- 存在加载") :
                                    console.log("Login -----------------不存在 存在加载");
                                e[n][c].preLoad && e[n][c].preLoad();
                                s.default.open(r.UIID.UIToast, { msg: "广告正在加载中" });
                                t.updateCheckCall.push({ cb: o, bool: !1 });
                            }
                        }
                    },
                    hide: function(t, o) {
                        void 0 === t && (t = 1);
                        e[t][o].hide();
                    },
                    preLoad: function() {},
                    destory: function() {}
                };
                AdView.addAdCallBase({ 1: o });
            };
            n([u(cc.Material)], e.prototype, "G_Mat", void 0);
            n([u(cc.Material)], e.prototype, "W_Mat", void 0);
            n([u(cc.Camera)], e.prototype, "camera", void 0);
            return n([d], e);
        })(cc.Component));
o.default = h;